/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Matakuliah;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author advent
 */
public class MatakuliahTableModel extends AbstractTableModel{
 private List<Matakuliah> makul = new ArrayList<Matakuliah>();

    public MatakuliahTableModel(List <Matakuliah> makul) {
        this.makul = makul;
    }

    public void delete(int row){
        makul.remove(row);
        fireTableRowsDeleted(row, row);
    }

    public void update(int row, Matakuliah kat) {
       makul.set(row, kat);
       fireTableRowsUpdated(row, row);
    }


    public int getRowCount() {
        return makul.size();
    }

    public int getColumnCount() {
        return 2;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Matakuliah k = makul.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return k.getIdmatakuliah();
            case 1:
                return k.getNamaMatakuliah();
            default:
                return "";
        }
    }

    @Override
        public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "Id Matakuliah";
            case 1:
                return "Nama Matakuliah";
            default:
                return "";
        }
    }
}
